package guda.house.biz.form.rule;

import guda.house.biz.util.PriceUtil;
import guda.house.dal.dataobject.BankChargeRuleDO;

import javax.validation.constraints.NotNull;

/**
 * Created by well on 15/11/11.
 */
public class BankChargeRuleEditForm extends BankChargeRuleForm{

    @NotNull(message = "不能为空")
    private Long ruleId;

    public Long getRuleId() {
        return ruleId;
    }

    public void setRuleId(Long ruleId) {
        this.ruleId = ruleId;
    }

    public void initForm(BankChargeRuleDO bankChargeRuleDO){
        setRuleId(bankChargeRuleDO.getRuleId());
        setRuleStatus(bankChargeRuleDO.getRuleStatus());
        if(bankChargeRuleDO.getMaxValue()!=null) {
            setMaxValue(PriceUtil.formatCNYNoGroup(Long.valueOf(bankChargeRuleDO.getMaxValue())));
        }
        setVarId(bankChargeRuleDO.getVarId());
        if(bankChargeRuleDO.getChargeUnit()!=null) {
            setChargeUnit(PriceUtil.formatFeeChargeNoGroup(Long.valueOf(bankChargeRuleDO.getChargeUnit())));
        }
        setVillageId(bankChargeRuleDO.getVillageId());
        if(bankChargeRuleDO.getMaxFee()!=null) {
            setMaxFee(PriceUtil.formatCNYNoGroup(Long.valueOf(bankChargeRuleDO.getMaxFee())));
        }
    }

    public BankChargeRuleDO toDO(){
        BankChargeRuleDO bankChargeRuleDO = super.toDO();
        bankChargeRuleDO.setRuleId(ruleId);
        return bankChargeRuleDO;
    }
}
